package com.atgion.manager.service.impl;


import com.atgion.manager.mapper.PictureCategoryMapper;
import com.atgion.manager.service.PictureCategoryService;
import com.atgion.spzx.model.entity.ImageManagement.PictureCategory;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.xiaoymin.knife4j.core.util.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PictureCategoryServiceImpl extends ServiceImpl<PictureCategoryMapper, PictureCategory> implements PictureCategoryService {
   @Autowired
    PictureCategoryMapper pictureCategoryMapper;

    @Override
    public List<PictureCategory> findByParentId(Long categoryId) {
        List<PictureCategory> list = lambdaQuery()
                .eq(PictureCategory::getCategoryId, categoryId)
                .eq(PictureCategory::getIsDeleted,0)
                .orderByAsc(PictureCategory::getOrderNum)
                .list();

        if(!CollectionUtils.isEmpty(list)) {
            // 遍历分类的集合，获取每一个分类数据
            list.forEach(category -> {
                category.setHasChildren(lambdaQuery().eq(PictureCategory::getCategoryId,category.getId()).list().size()>0);
            });
        }
        return list;
    }


}
